package com.zhy.sping.service.impl;

import com.zhy.sping.dao.OssLogDao;
import com.zhy.sping.entity.OssLog;
import com.zhy.sping.service.intf.OssLogService;
import com.zhy.sping.util.AliOssUtil;
import com.zhy.sping.util.FileUtil;
import com.zhy.sping.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Service
public class OssLogServiceImpl implements OssLogService {
    //private Logger logger= LoggerFactory.getLogger(OssServiceImpl.class);
    @Autowired
    private OssLogDao dao;
    @Override
    public R uploadImg(MultipartFile file) {
        //logger.info("开始执行图片上传");
        //校验图片不为空
        if (!file.isEmpty()){
            //进行重命名
            String tename = FileUtil.tename(file.getOriginalFilename());
            try {
                //添加到oss   得到路径
                String url = AliOssUtil.upload(tename, file.getInputStream());
                //校验路径
                if (StringUtils.hasLength(url)){
                    //更新数据库      更新记录
                   // dao.insert(new OssLog());

                    //并返回
                }
            } catch (IOException e) {
                e.printStackTrace();
                //logger.error("文件上传异常-"+fn);
            }
        }
        return null;
    }

    @Override
    public R uploadVedio(MultipartFile file) {
        return null;
    }

    @Override
    public R uploadText(MultipartFile file) {
        return null;
    }
}
